/**
 * @file       EditField_test.cpp
 * @brief      TODO
 * @author     Huabo Zheng
 * @date       Jan 12, 2012
 * @Copyright  2012, www.netgear.com Inc. All rights reserved.
 */

#include "EditField.h"
#include "gtest/gtest.h"
#include "errorcode.h"
#include "Char.h"
#include "Panel.h"
#include "typedefine.h"
namespace NS_LCD_AFW
{
class CEditField_test: public ::testing::Test
{
public:
	virtual void SetUp()
	{
		OBJ_NEW(CPanel,m_pMainPanel);
		m_pMainPanel->create("test",CRect(0,0,10,2));
	}
	virtual void TearDown()
	{
		OBJ_DESTORY(m_pMainPanel);
	}

protected:
	CPanel *m_pMainPanel;
};
TEST_F(CEditField_test,test_defualtConstruction)
{
	CEditField *pField = new CEditField();
	EXPECT_TRUE(pField->isHightlightable());
	EXPECT_TRUE(pField->isFocusable());
	OBJ_DESTORY(pField);
}
TEST_F(CEditField_test,test_setText)
{
	CEditField *pField = new CEditField();
	EXPECT_EQ(ERR_SUCCESS, pField->create("test",CRect(0,0,5,1)));
	EXPECT_EQ(ERR_SUCCESS, pField->setText("abc123!@#."));
	EXPECT_EQ("abc123!@#.", pField->getText());

	EXPECT_EQ(ERR_SUCCESS, pField->setText(""));
	EXPECT_EQ("", pField->getText());
	OBJ_DESTORY(pField);
}
TEST_F(CEditField_test,test_getText)
{
	CEditField *pField = new CEditField();
	EXPECT_EQ(ERR_SUCCESS, pField->create("test",CRect(0,0,5,1)));
	EXPECT_EQ(ERR_SUCCESS, pField->setText("abc123!@#."));
	EXPECT_EQ("abc123!@#.", pField->getText());

	EXPECT_EQ(ERR_SUCCESS, pField->setText(""));
	EXPECT_EQ("", pField->getText());
	OBJ_DESTORY(pField);
}
TEST_F(CEditField_test,test_addChar)
{
	CEditField *pField = new CEditField();
	EXPECT_EQ(ERR_NULL_POINTER, pField->addChar(NULL));
	CChar *pChar = new CChar();
	pChar->setChar('a');
	EXPECT_EQ(ERR_SUCCESS, pField->addChar(pChar));
	EXPECT_EQ("a", pField->getText());
	OBJ_DESTORY(pField);
}
TEST_F(CEditField_test,test_onSetFocus)
{
	CEditField *pField = new CEditField();
	EXPECT_EQ(ERR_SUCCESS, pField->create("test",CRect(0,0,10,10),this->m_pMainPanel));

	EXPECT_FALSE(pField->hasFocus());
	EXPECT_FALSE(pField->isHightlight());
	EXPECT_EQ(ERR_SUCCESS, pField->setFocus(true));
	EXPECT_FALSE(pField->isHightlight());

	EXPECT_EQ(ERR_SUCCESS, pField->setFocus(false));

	EXPECT_EQ(ERR_SUCCESS, pField->setHightlight(true));
	EXPECT_TRUE(pField->isHightlight());

	EXPECT_FALSE(pField->hasFocus());
	EXPECT_EQ(ERR_SUCCESS, pField->setFocus(true));
	EXPECT_FALSE(pField->isHightlight());

	OBJ_DESTORY(pField);
}
TEST_F(CEditField_test,test_onLostFocus)
{

}
TEST_F(CEditField_test,test_onHightlight)
{

}
TEST_F(CEditField_test,test_onUnHightlight)
{

}
TEST_F(CEditField_test,test_onSize)
{

}
TEST_F(CEditField_test,test_onRightKeyPress)
{
	CFrame *pField = new CEditField();
	EXPECT_EQ(ERR_SUCCESS, pField->create("testField",CRect(0,0,2,2),this->m_pMainPanel));

	EXPECT_EQ(ERR_SUCCESS, pField->setHightlight(true));
	EXPECT_EQ(ERR_SUCCESS, pField->onRightKeyPress());
	EXPECT_FALSE(pField->isHightlight());


	EXPECT_EQ(ERR_NO_CHANGE, pField->setHightlight(false));
	EXPECT_EQ(ERR_SUCCESS, pField->onRightKeyPress());
	EXPECT_TRUE(pField->isHightlight());
	EXPECT_TRUE(pField->hasFocus());

	EXPECT_EQ(ERR_SUCCESS, ((CEditField *)pField)->setText("abcdefgh"));
	EXPECT_EQ(ERR_SUCCESS, pField->onRightKeyPress());
	EXPECT_FALSE(pField->isHightlight());
	EXPECT_FALSE(pField->hasFocus());

	OBJ_DESTORY(pField);
}
TEST_F(CEditField_test,test_onLeftKeyPress)
{
	CFrame *pField = new CEditField();
	EXPECT_EQ(ERR_SUCCESS, pField->create("testField",CRect(0,0,2,2),this->m_pMainPanel));
	EXPECT_EQ(ERR_SUCCESS, pField->setHightlight(true));
	EXPECT_EQ(ERR_EVENT_UN_HANDLED, pField->onLeftKeyPress());

	EXPECT_EQ(ERR_SUCCESS, pField->setHightlight(false));
	EXPECT_EQ(ERR_SUCCESS, pField->onLeftKeyPress());
	EXPECT_TRUE(pField->isHightlight());
	EXPECT_TRUE(pField->hasFocus());

	EXPECT_EQ(ERR_SUCCESS, ((CEditField *)pField)->setText("abcdefgh"));
	EXPECT_EQ(ERR_SUCCESS, pField->setHightlight(false));
	EXPECT_EQ(ERR_SUCCESS, pField->onLeftKeyPress());
	EXPECT_TRUE(pField->isHightlight());
	EXPECT_TRUE(pField->hasFocus());

	OBJ_DESTORY(pField);
}
TEST_F(CEditField_test,test_onUpKeyPress)
{
	CFrame *pField = new CEditField();
	EXPECT_EQ(ERR_SUCCESS, pField->create("testField",CRect(0,0,2,2)));
	EXPECT_EQ(ERR_NO_CHANGE, pField->setHightlight(false));
	EXPECT_EQ(ERR_EVENT_UN_HANDLED, pField->onUpKeyPress());

	EXPECT_EQ(ERR_SUCCESS, pField->setHightlight(true));
	EXPECT_EQ(ERR_EVENT_UN_HANDLED, pField->onUpKeyPress());
	EXPECT_FALSE(pField->isHightlight());
	EXPECT_FALSE(pField->hasFocus());

	OBJ_DESTORY(pField);
}
TEST_F(CEditField_test,test_onDownKeyPress)
{
	CFrame *pField = new CEditField();
	EXPECT_EQ(ERR_SUCCESS, pField->create("testField",CRect(0,0,2,2)));
	EXPECT_EQ(ERR_NO_CHANGE, pField->setHightlight(false));
	EXPECT_EQ(ERR_EVENT_UN_HANDLED, pField->onDownKeyPress());

	EXPECT_EQ(ERR_SUCCESS,((CEditField*)pField)->setText("abcdef"));
	EXPECT_EQ(ERR_SUCCESS, pField->setFocus(true));
	EXPECT_EQ(ERR_SUCCESS, pField->setHightlight(true));
	EXPECT_EQ(ERR_SUCCESS, pField->onDownKeyPress());
	EXPECT_TRUE(pField->isHightlight());
	EXPECT_TRUE(pField->hasFocus());

	EXPECT_EQ(ERR_NO_CHANGE, pField->setHightlight(true));
	EXPECT_EQ(ERR_EVENT_UN_HANDLED, pField->onDownKeyPress());
	EXPECT_FALSE(pField->isHightlight());
	EXPECT_FALSE(pField->hasFocus());

	OBJ_DESTORY(pField);
}
TEST_F(CEditField_test,test_onEnterKeyPress)
{
	CFrame *pField = new CEditField();
	EXPECT_EQ(ERR_SUCCESS, pField->create("testField",CRect(0,0,2,2),this->m_pMainPanel));
	EXPECT_EQ(ERR_SUCCESS, pField->setHightlight(true));
	EXPECT_EQ(ERR_SUCCESS, pField->onEnterKeyPress());
	EXPECT_EQ(ERR_NO_CHANGE, pField->setHightlight(false));
	EXPECT_EQ(ERR_SUCCESS, pField->onEnterKeyPress());
	EXPECT_TRUE(pField->isHightlight());
	EXPECT_TRUE(pField->hasFocus());

	EXPECT_EQ(ERR_SUCCESS, ((CEditField *)pField)->setText("abcdefgh"));
	EXPECT_EQ(ERR_SUCCESS, pField->onEnterKeyPress());
	EXPECT_FALSE(pField->isHightlight());
	EXPECT_FALSE(pField->hasFocus());

	OBJ_DESTORY(pField);

}
TEST_F(CEditField_test,test_onEscKeyPress)
{
	CFrame *pField = new CEditField();
	EXPECT_EQ(ERR_SUCCESS, pField->create("testField",CRect(0,0,2,2)));
	EXPECT_EQ(ERR_SUCCESS, pField->setHightlight(true));
	EXPECT_EQ(ERR_EVENT_UN_HANDLED, pField->onEscKeyPress());

	EXPECT_EQ(ERR_SUCCESS, pField->setHightlight(false));
	EXPECT_EQ(ERR_SUCCESS, pField->onEscKeyPress());
	EXPECT_TRUE(pField->isHightlight());
	EXPECT_TRUE(pField->hasFocus());

	EXPECT_EQ(ERR_SUCCESS, ((CEditField *)pField)->setText("abcdefgh"));
	EXPECT_EQ(ERR_SUCCESS, pField->setHightlight(false));
	EXPECT_EQ(ERR_SUCCESS, pField->onEscKeyPress());
	EXPECT_TRUE(pField->isHightlight());
	EXPECT_TRUE(pField->hasFocus());

	OBJ_DESTORY(pField);
}
} /* namespace NS_LCD_AFW */
